﻿using UnityEngine;
using System.Collections;

public class Codex
{
	// Members

	public bool isLooping
	{
		get;
		private set;
	}

	public bool needMasterPass
	{
		get;
		private set;
	}

	public int securityLevel
	{
		get;
		private set;
	}

	public string title
	{
		get;
		private set;
	}

	public string text
	{
		get;
		private set;
	}


	public Codex(string textPath, bool looping, int seclvl, bool masterPass)
	{
		needMasterPass		= masterPass;
		isLooping			= looping;
		securityLevel		= seclvl;

		LoadTextAndProcess(textPath);
	}

	/// <summary>
	/// 텍스트 로드 후 가공
	/// </summary>
	/// <param name="path"></param>
	void LoadTextAndProcess(string path)
	{
		TextAsset textRes	= ResourceDepot.Load<TextAsset>(Constants.Path.texts + path);
		string loadedText	= textRes.text;
		textRes				= null;

		string [] split		= loadedText.Split(new char[] { '\n' }, 2);		// 줄바꿈 문자로 1번만 나눈 뒤 첫번째줄은 제목, 두번째부터는 내용으로

		title				= split[0];
		text				= split.Length > 1? split[1] : split[0];
	}
}
